""" System imports """
import os, sys
import logging
import logging.config

""" Other modules """
import pygame

""" Game """
from constants import *
import settings
import level
import ui.mainmenu
import player
from eventrouter import eventpanel
import inputhandler
import session
from mixboard import mixboard
from view import View
import featurebroker

if __name__ == "__main__":
    
    pygame.init()
    pygame.display.set_caption(GAME_CAPTION)
    # Set up the screen
    screen = pygame.display.set_mode(SCREEN_SIZE)    
    
    clock = pygame.time.Clock()
    
    # Set up logging
    logging.config.fileConfig("logging.conf")
#    logging.basicConfig(level=logging.DEBUG)
    logger = logging.getLogger(GAME_NAME_LC)
    logger.setLevel(logging.DEBUG)
    
    logger.debug("Initializing Main. Welcome back to EpicQuest, master.")
    
    #currentlevel = level.Level("level1.txt")
    #player = player.Player((1,0))
    
    # Now we are ready to start the game.   

    mainmenu = ui.mainmenu.MainMenu()
#    mainmenu.start_music(os.path.join('music','ThePrelude.ogg'))
    
    level1 = level.Level()
    level1.load_level(os.path.join("levels","level1.txt"))
    #level1.inst().dump_level()
    current_session = mainmenu
    
    while True:
        clock.tick(30)
        screen = pygame.display.get_surface()
        
        """ Clear the screen """
        screen.fill((0,0,0))
        
        """ Handle new input """
        inputhandler.handle_input()
        
        """ update the menu """
        if current_session.update() == 1:
            current_session.end_session()
            current_session = level1
#            current_session.queue_music(os.path.join("music","MistsofTime.ogg"))
#            mixboard.set_volume(0.7)
        
        """ Draw the updated stuff """
        #currentlevel.draw(screen)
        #player.draw(screen)
        
        current_session.draw(screen)
        
        """ Update the screen and pump events """
        pygame.display.flip()
        pygame.event.pump()

